/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 08.11.2003 by RST.
// $Id: entity_state_t.java,v 1.5 2005/06/05 15:21:47 salomo Exp $
using System;
using Math3D = Suake2.UI.util.Math3D;
using QuakeFile = Suake2.UI.util.QuakeFile;
namespace Suake2.UI.game
{
	
	public class entity_state_t : System.ICloneable
	{
		/// <summary>entity_state_t is the information conveyed from the server
		/// in an update message about entities that the client will
		/// need to render in some way. 
		/// </summary>
		public entity_state_t(edict_t ent)
		{
			this.surrounding_ent = ent;
			if (ent != null)
				number = ent.index;
		}
		
		/// <summary>edict index. TODO: this is critical. The index has to be proper managed. </summary>
		public int number = 0;
		// TODO: why was this introduced?
		public edict_t surrounding_ent = null;
		public float[] origin = new float[]{0, 0, 0};
		public float[] angles = new float[]{0, 0, 0};
		
		/// <summary>for lerping. </summary>
		public float[] old_origin = new float[]{0, 0, 0};
		public int modelindex;
		/// <summary>weapons, CTF flags, etc. </summary>
		public int modelindex2, modelindex3, modelindex4;
		public int frame;
		public int skinnum;
		/// <summary>PGM - we're filling it, so it needs to be unsigned. </summary>
		public int effects;
		public int renderfx;
		public int solid;
		// for client side prediction, 8*(bits 0-4) is x/y radius
		// 8*(bits 5-9) is z down distance, 8(bits10-15) is z up
		// gi.linkentity sets this properly
		public int sound; // for looping sounds, to guarantee shutoff
		public int event_Renamed; // impulse events -- muzzle flashes, footsteps, etc
		// events only go out for a single frame, they
		// are automatically cleared each frame
		
		/// <summary>Writes the entity state to the file. </summary>
		public virtual void  write(QuakeFile f)
		{
			f.writeEdictRef(surrounding_ent);
			f.writeVector(origin);
			f.writeVector(angles);
			f.writeVector(old_origin);
			
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) modelindex);
			
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int32) modelindex2);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Int32) modelindex3);
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Int32) modelindex4);
			
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Int32) frame);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Int32) skinnum);
			
			System.IO.BinaryWriter temp_BinaryWriter7;
			temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter7.Write((System.Int32) effects);
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Int32) renderfx);
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Int32) solid);
			
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Int32) sound);
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Int32) event_Renamed);
		}
		
		/// <summary>Reads the entity state from the file. </summary>
		public virtual void  read(QuakeFile f)
		{
			surrounding_ent = f.readEdictRef();
			origin = f.readVector();
			angles = f.readVector();
			old_origin = f.readVector();
			
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			modelindex = temp_BinaryReader.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			modelindex2 = temp_BinaryReader2.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			modelindex3 = temp_BinaryReader3.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			modelindex4 = temp_BinaryReader4.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			frame = temp_BinaryReader5.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			skinnum = temp_BinaryReader6.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			effects = temp_BinaryReader7.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			renderfx = temp_BinaryReader8.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			solid = temp_BinaryReader9.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			sound = temp_BinaryReader10.ReadInt32();
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			event_Renamed = temp_BinaryReader11.ReadInt32();
		}
		
		
		public virtual entity_state_t getClone()
		{
			entity_state_t out_Renamed = new entity_state_t(this.surrounding_ent);
			out_Renamed.set_Renamed(this);
			return out_Renamed;
		}
		
		public virtual void  set_Renamed(entity_state_t from)
		{
			number = from.number;
			Math3D.VectorCopy(from.origin, origin);
			Math3D.VectorCopy(from.angles, angles);
			Math3D.VectorCopy(from.old_origin, old_origin);
			
			modelindex = from.modelindex;
			modelindex2 = from.modelindex2;
			modelindex3 = from.modelindex3;
			modelindex4 = from.modelindex4;
			
			frame = from.frame;
			skinnum = from.skinnum;
			effects = from.effects;
			renderfx = from.renderfx;
			solid = from.solid;
			sound = from.sound;
			event_Renamed = from.event_Renamed;
		}
		
		public virtual void  clear()
		{
			//TODO: this is critical. The index has to be proper managed.
			number = 0;
			surrounding_ent = null;
			Math3D.VectorClear(origin);
			Math3D.VectorClear(angles);
			Math3D.VectorClear(old_origin);
			modelindex = 0;
			modelindex2 = modelindex3 = modelindex4 = 0;
			frame = 0;
			skinnum = 0;
			effects = 0;
			renderfx = 0;
			solid = 0;
			sound = 0;
			event_Renamed = 0;
		}
		//UPGRADE_TODO: The following method was automatically generated and it must be implemented in order to preserve the class logic. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1232'"
		virtual public System.Object Clone()
		{
			return null;
		}
	}
}